// pages/article_info/article_info.js
var wxParse = require('../../wxParse/wxParse.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    aricle_detail: '',
    articleDescription: "", //文章详情
    article_content: '',
    thumb: '',
    title: '',
    wechat_url: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var id = options.id
    that.setData({
      id: id
    })

    wx.showShareMenu({
      menus: ['shareAppMessage','shareTimeline'],
      success(res) {
      },
      fail(e) {
        console.log(e)
      }
    })

    let url = decodeURIComponent(options.wechat_url)
    this.setData({
      wechat_url: url
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  get_article_detail() {
    let that = this
    app.request("/get_aricle_detail", {
      data: {
        id: that.data.id
      }
    }).then(res => {
      console.log(res, '66666');
      that.setData({
        title: res.data.article_detail.title,
        thumb: res.data.article_detail.img_one,
        // aricle_detail: res.data.article_detail,
        // article_content : res.data.article_detail.content.replace(/src="/gi, 'src="https://vip.join.ink'),
        // article_content: res.data.article_detail.content.replace(/<img/gi, '<img style="max-width:90vw;height:auto;margin:10px auto;display:block;" ').replace(/src="/gi, 'src="https://vip.join.ink').replace(/<embed/gi, '<video style="max-width:90vw;height:auto;margin:10px auto;display:block;"'),
        // article_content: res.data.article_detail.content.replace(/<img/gi, '<img style="max-width:90vw;height:auto;margin:10px auto;display:block;" ').replace(/src="/gi, 'src="https://vip.join.ink'),
        wechat_url: res.data.article_detail.wechat_url
      })



      // wxParse.wxParse("articleDescription", "html", res.data.article_detail.content.replace(/src="/gi, 'src="https://vip.join.ink').replace(/<embed/gi, '<video style="max-width:90vw;height:auto;margin:10px auto;display:block;"'), that, 0);
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    var that = this
    that.get_article_detail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  getmessage(e){
    console.log(e,'666666666666666666666666')
    let obj = e.detail.data[e.detail.data.length - 1];
    console.log(obj,'99999999999999999999999999999999999999999999999999999999')
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var that = this
    if (res.from === 'button') {
      console.log("来自页面内转发按钮");
      console.log(res.target);
    } else {
      console.log("来自右上角转发菜单")
      return {
        title: that.data.title,
        path: '/pages/share_wechat/share_wechat?url=' + encodeURIComponent(that.data.wechat_url),
        imageUrl: 'https://vip.join.ink/' + that.data.thumb,
        success: (res) => {
          console.log("转发成功", res);
          wx.showToast({
            title: '分享成功~',
            icon: 'success',
            duration: 1800
          })
        },
        fail: (res) => {
          console.log("转发失败", res);
        }
      }
    }

  }
})